﻿var G_WebRoot = '/'+(window.location.pathname.indexOf('/')==0?window.location.pathname.split('/')[1]:window.location.pathname.split('/')[0])+'/';
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
var JBF=(function(){
	return{	
		doc: window.document,
		strIsNull: function(str){
			if(str&&typeof(str)=='string'){
				if(str.length>0){
					return true;
				}
				return false;
			}
			return false;
		},
		el: function(id){
			if( id && typeof(id) == 'string' ){
				return JBF.doc.getElementById(id);
			}
		},
		setObjValue:function(condition,srcObj, defualtValue){
			if(condition){
				return srcObj;
			}else{
				if (defualtValue){
					return defualtValue;
				}
			}
			return "";
		},
		/**
		*通过名称，获取当前元素值
		*/
		elByName: function(name){
			if( name && typeof(name) == 'string' ){
				return JBF.doc.getElementsByName(name);
			}
		},
		mockEvent:function(obj,eventName){
			var event=null;
			if(document.all){
				event=document.createEventObject();	
				obj.fireEvent("on"+eventName,event);
			}else{
				document.createEvent("MouseEvents");
				event.initMouseEvent(eventName,true,true,document.defaultView,0,0,0,0,0,false,false,false,false,0,null);
				obj.dispatchEvent(event);
			}
		},
		/**
		 * 通过className名称获取一层子节点信息
		 * @param obj
		 * @param className
		 * @returns
		 */
		elChildForClassName:function(obj,className){
			if(obj&&obj.childNodes){
				var subNodes=obj.childNodes;
				for(var i=(subNodes.length-1);i>-1;i--){
					if(subNodes[i].className&&subNodes[i].className==className){
						return	subNodes[i];
					}
				}	
			}
		},
		/**
		 * 得到页面版本信息
		 * @returns
		 */
		getBrowseVersion:function(){
			var agent=navigator.userAgent;
			if(agent.indexOf("MSIE")){
				agent=(agent.substring(agent.indexOf("MSIE")+4,agent.indexOf("Windows")));
				agent=Number(agent.replace(";", ""));
				return agent;
			}
			return null;
		},
		getBrowseIsIe:function(){
			var agent=navigator.userAgent;
			if(agent.indexOf("MSIE")){
				return true;
			}
			return false;
		},
		elAllChildForClassName:function(obj,className,childs){
			if(obj&&obj.childNodes){
				var subNodes=obj.childNodes;
				for(var i=(subNodes.length-1);i>-1;i--){
					if(subNodes[i].className&&subNodes[i].className==className){
						childs.push(subNodes[i]);
						if(document.all){
							JBF.elAllChildForClassName(subNodes[i],className,childs);
						}
					}
				}	
			}
		},
		/**
		*得到当前事件
		*/
		getEvent:function(event){
			return event?event:(window.event || arguments[0]);
		},
		/**
		*得到键盘按钮的ascII值
		*/
		getKeyValue:function(event){
			if(event.keyCode){
				return event.keyCode;		
			}else{
				return event.charCode;	
			}
		},
		
		/**
		 * 得到下一个节点。兼容ie9
		 */
		getNextElement:function(node){
			var x = node.nextSibling;   
			if(x){
				while (x && x.nodeType != 1){   
					x = x.nextSibling;   
				}   
				return x; 
			} 
			return null;   
		},
		/**
		 * 得到上一个节点。兼容ie9
		 */
		getPreElement:function(node){
			var x = node.previousSibling;   
			if(x){
				while (x && x.nodeType != 1){   
					x = x.previousSibling;   
				}   
				return x; 
			} 
			return null;  
		},
		
		/**
		 * 在目标节点之后插入新节点
		 * 
		 * @param newEl
		 * @param targetEl
		 * @returns
		 */
		insertAfter :function(newEl, targetEl) {
			var parentEl = targetEl.parentNode;
			if (parentEl.lastChild == targetEl) {
				parentEl.appendChild(newEl);
			} else {
				parentEl.insertBefore(newEl, targetEl.nextSibling);
			}
		},
		
		/**
		 * 输入校验
		 * @param obj
		 * @param regex
		 * @param tipText
		 * @returns
		 */
		inputCheck :function (obj,regex,tipText){
			var patrn = regex;
			if (obj.value.match(patrn)) {
				obj.style.borderColor = "#9cb3e2";
				var showTipDiv = JBF.el(obj.name + "_TipDiv");
				if (showTipDiv) {
					JBF.el(obj.name + "_TipDiv").style.display = "none";
				}
				return;
			} else {
				if (obj.value == "") {
					return;
				} else {
					this.showTipText(obj, tipText);
				}
			}
		},
		
		/**
		 * 显示校验未通过时提示信息
		 * @param obj
		 * @param tipText
		 * @returns
		 */
		showTipText : function (obj, tipText) {
			var showTipDiv = JBF.el(obj.name + "_TipDiv");
			if (!showTipDiv) {
				showTipDiv = document.createElement("div");
				showTipDiv.setAttribute("id", obj.name + "_TipDiv");
				this.insertAfter(showTipDiv, obj);
			}
			showTipDiv.innerHTML = tipText;
			showTipDiv.className = "showTipDiv";
			showTipDiv.style.display = "block";
			showTipDiv.style.left = JBF.getAbsX(obj) + "px";
			showTipDiv.style.width = JBF.getObjWidth(obj) - 2 + "px";
			showTipDiv.style.top = JBF.getAbsY(obj) + JBF.getObjHeight(obj) + "px";
			obj.style.borderColor = "#FF0000";
		},
		
		/**
		 * 隐藏tip提示层
		 */
		hiddenTipDiv : function (obj){
			var showTipDiv = JBF.el(obj.name + "_TipDiv");
			if (showTipDiv) {
				obj.style.borderColor = "#D0DABB";
				JBF.el(obj.name + "_TipDiv").style.display = "none";
			}
		},
		
		/**
		 * 数值录入框
		 * @param input
		 * @returns
		 */
		replaceNum:function(input){
			var pattern = new RegExp(/[^0-9]/g);
			this.inputCheck(input, /^\d+$/, "该字段只能输入整数");
			input.value=input.value.replace(pattern,''); 
		},
		replaceDate:function(input){
			var pattern = new RegExp(/[^0-9]/g);
			var value=input.value.replace(pattern,''); 
			//value=input.value.replace(/\D/g,''); // onafterpaste="this.value=this.value.replace(/\D/g,'')">
			var key5=0;
			var key6=0;
			var year="1900";
			var month="12";
			if(value.length>4){
				key5=value.substring(4,5);
				year=Number(value.substring(0,4));
				if(key5>1){
					input.value=value.substring(0,4);
					return;
				}
			}
			if(value.length>5){
				key6=value.substring(5,6);
				month=value.substring(4,6);
				if(key5==1&&key6>2){
					input.value=value.substring(0,5);
					return;
				}
			}
			if(value.length>6){
				key7=value.substring(6,7);
				key6=Number(month);
				if(key6==2){
					if(key7>2){
						input.value=value.substring(0,6);
						return;
					}
				}else{
					if(key7>3){
						input.value=value.substring(0,6);
						return;
					}
				}
			}
			if(value.length>7){
				key7=value.substring(6,7);
				key8=value.substring(7,8);
				key6=Number(month);
				if(key6==2){
					if(key7>1){
						if(year%4!=0&&key8>8){//来进行判断年的类型
							input.value=value.substring(0,7);
							return;
						}
					}
				}else{
					if(key7>2){
						if(key6==1||key6==3||key6==5||key6==7||key6==8||key6==10||key6==12){
							if(key8>1){
								input.value=value.substring(0,7);
								return;
							}
						}else{
							if(key8>0){
								input.value=value.substring(0,7);
								return;
							}
						}//如果输入的是3，则个位只允许输入0或1、
					}
				}
			}
			if(value.length>8){
				input.value=value.substring(0,8);
			}else{
				input.value=value;
			}
		},
		/**
		 * 货币录入框
		 * @param input
		 * @param numCount
		 * @returns
		 */
		replaceMoney:function(obj,numCount){
			var formatMoneyString=function formatMoneyString(sString) 
			{
				if (!sString) {
					return "0.00";
				}
				var szRet = "";
				var v = sString.replace(/(^\s*)|(\s*$)/g,"");  //去除前后空格
				if (v.length!=""){
				//添加小数点
					var index = v.indexOf('.');
					var szresult = "";
					if (index == -1){
						if(v.length == 0){
							szresult = "";
						}else if(v.length == 1){
							szresult = "0.0" + v;
						}else if(v.length == 2){
							szresult = "0." + v;
						}else{
							szresult = v.substring(0,v.length-2) + "." + v.substring(v.length-2,v.length);
						}
					}else if(index == v.length - 1){
						szresult = v + "00";
					}
					else if(index == v.length - 2){
						szresult = v + "0";
					}
					else {
						szresult = v;
					}
					index = szresult.indexOf(".");
					var tempdecimalpart = szresult.substring(index,index + 3);
					var temp = szresult.substring(0,index);
					index = temp.length % 3;
					var tempintegerpart = temp.substring(0,index);
					for(;index<temp.length;index+=3){
						if (tempintegerpart == ""){
							tempintegerpart = tempintegerpart + temp.substring(index,index+3);
						}
						else{
							tempintegerpart = tempintegerpart + "," + temp.substring(index,index+3);
						}
					}
					szRet = tempintegerpart + tempdecimalpart;
				}
				return szRet;
			};	
			var keyCode=JBF.getKeyValue(JBF.getEvent());
			if(keyCode == 9 || keyCode == 13 ) {return true;}
			var v = obj.value;	
			v = v.replace(/(^\s*)|(\s*$)/g,"").replace(/(,)/g,"");
			var pattern = new RegExp(/[^(0-9|,|.)]/g);
			v=v.replace(pattern,"");
			if((keyCode>=96 && keyCode<=105)|| keyCode == 111 ||(keyCode>=48 && keyCode<=57)||keyCode==13 ||keyCode==9|| keyCode==8){
			    var indexDot = v.indexOf(".");
			    v = v.substring(0, indexDot) + v.substring(indexDot+1);
				while(v.length>3 && v.substring(0,1)=='0') {
					 v = v.substring(1);
				} 
				if (v != ""){
					showmsg =formatMoneyString(v);
					obj.value = showmsg;
				}
			}else{
				obj.value=showmsg;
			}
		},
		getNumber:function(numValue){
			return JBF.getDecimal(numValue,0);
		},
		getDecimal:function(decValue,numCount){
			if(decValue){
				var value  = decValue.toString().replace(/\$|\,/g,'');
				var isNegative=false;
				isNegative = (decValue == (decValue = Math.abs(decValue))) == false;
				var splitLen=3;
				var returnValue="";
				var num="";//存放小数
				if(value.indexOf(".")>-1){
					num=value.substring(value.indexOf("."));//用来约束小数位个数
					if(numCount&&num.length>(numCount+1)){
						decValue=decValue.substring(0,decValue.length-1);
						return;
					}
					value=value.substr(0,value.indexOf("."));
				}
				while(value.length>splitLen){//重复加,
					returnValue=(","+value.substr(value.length-splitLen,splitLen))+returnValue;
					value=value.substr(0,value.length-splitLen);
				}
				if(value.length>0){
					returnValue=value+returnValue;
				}
				if(isNegative){
					return "-"+returnValue+num;
				}
				return returnValue+num;//重整后送还input的value
			}else{
				return 0;
			}
		},
		getDate:function(date){
			var pattern = new RegExp(/[^0-9]/g);
			if(date){
				date=date.replace(pattern,'');
				return date.substring(0,8);
			}else{
				return "";
			}
		},
		
		getTimestamp:function(date){
			return date.replace("T"," ");
		},
		
		getFormatValue:function(value,type) {
			switch (type){
				case "date":
					value = JBF.getDate(value);
					break;
				case "timestamp":
					value = JBF.getTimestamp(value);
					break;
				case "number":
					value = JBF.getNumber(value);
					break;
				case "decimal":
					value = JBF.getDecimal(value,2);
					break;
				default:
					break;
			}
			return value;
		},
		/**
		*得到执行事件的对象
		*/
		getEventTarget:function(ev){
			if(ev.srcElement){
				return ev.srcElement;	
			}else{
				return ev.target;	
			}
		},
		/**
		*得到屏幕高度
		*/
		getScreenHeight:function(){
			var pageHeight=window.innerHeight;
			if(typeof pageHeight!="number"){
				if(document.compatMode=="CSS1Compat"){
					pageHeight=document.documentElement.clientHeight;
				}else{
					pageHeight=document.body.clientHeight;
				}
			}
			return pageHeight;	 
		},
		/**
		*得到屏幕宽度
		*/
		getScreenWidth:function(){
			var pageWidth=window.innerWidth;
			if(typeof pageWidth!="number"){
				if(document.compatMode=="CSS1Compat"){
					pageWidth=document.documentElement.clientWidth;
				}else{
					pageWidth=document.body.width;
				}
			}
			return pageWidth;	 
		},
		/**
		 * 得到点击是的鼠标x位置
		 */
		pointerX:function(event){
			return event.pageX||(event.clientX +(document.documentElement.scrollLeft||document.body.scrollLeft)); 
	    },
		/**
		 * 得到点击是的鼠标y位置
		 */
		pointerY:function(event){
			return event.pageY||(event.clientY +(document.documentElement.scrollTop||document.body.scrollTop));
		},
		/**
		 * 
		 * @returns
		 */
		getObjHeight:function(obj){			
			if(document.all){
				return obj.offsetHeight;
			}
			return obj.clientHeight;	
		},
		getObjWidth:function(obj){			
			if(document.all){
				return obj.offsetWidth;
			}
			return obj.clientWidth;	
		},
		getAbsX:function(obj){
			o = obj;
			oLeft = o.offsetLeft;            
			while(o.offsetParent!=null) { 
				oParent = o.offsetParent;    
				oLeft += oParent.offsetLeft; 
				o = oParent; 
			} 
			return oLeft; 
		},
		getMouseX:function(event){
			var ev=JBF.getEvent(event);
			if(ev.screenX){
				return ev.screenX;
			}
			return 0;
		},
		getMouseY:function(event){
			var ev=JBF.getEvent(event);
			if(ev.screenY){
				return ev.screenY;
			}
			return 0;
		},
		getX:function(ev) {
			if (window.event) {
				return event.x;
			} else {
				return ev.pageX;
			}
		},
		getY:function(ev) {
			if (window.event) {
				return event.y;
			} else {
				return ev.pageY;
			}
		},
		getAbsY:function(obj){
			o = obj;
			oTop = o.offsetTop; 
			while(o.offsetParent!=null) 
			{  
				oParent = o.offsetParent; 
				oTop += oParent.offsetTop;  // Add parent top position 
				o = oParent; 
			} 
			return oTop; 
		},
		/**
		 * 对来获取对像中的所有再有滚动条的高度
		 * @param obj
		 * @returns
		 */
		getScrollTop:function(obj){
			var sh=0;
			(function(obj){			
				if(obj.scrollTop){
					sh+=obj.scrollTop;						
				}
				var parentNode=obj.parentNode;
				if(parentNode&&parentNode.nodeName!="BODY"){
					arguments.callee(obj.parentNode);
				}
			})(obj);
			return sh;
		},
		getStyleNum:function(obj){
			if(obj){
				obj=obj.replace("px","").replace("PX","");
				try{
					return Number(obj);
				}catch(e){
					return 0;
				}
			}
			return 0;
		},
		/**
		*根据不同的类型，获取不同的值，type
		**/
		getValue:function(name,type){
			if(name){
				var cty=JBF.el(name);
					if(cty){
						if(cty.nodeName=="INPUT"||cty.nodeName=="SELECT"){
							if(cty.type=="checkbox"||cty.type=="radio"){
								return JBF.getSubValues(JBF.elByName(name));
							}else if(type=="date"){
								var value=cty.value.replace(/[ ]/g,"");
								if(value&&value.length==8){
									return value.substring(0,4)+"-"+value.substring(4,6)+"-"+value.substring(6,8);
								}else{
									if(value.length>0&&value.length<=8){
										alert("日期格式不合法！");
										value="";
									}	
									return "";
								}
							}else if(type=="money"){
								var value=cty.value.replace(/[ ]/g,"");
								return value.replace(/\$|\,/g,"");
							}else{
								var value=cty.value.replace(/[ ]/g,"");
								return value;
							}		
						}else if(cty.nodeName=="DIV"||cty.nodeName=="TEXTAREA"){
							return cty.innerHTML;	
						}else{
							 return JBF.getSubValues(JBF.elByName(name)); 	
						}
				}
			}
			return "";
		},
		setValue:function(name,type,value){
			if(name){
				var cty=JBF.el(name);
				if(cty){
					if(cty.nodeName=="INPUT"){
						if(cty.type=="checkbox"){
							var values=value.split(",");
							JBF.setCheckValue(JBF.elByName(name),values,"check");
						}else if(cty.type=="radio"){
							JBF.setCheckValue(JBF.elByName(name),value,"radio");
						}else{
							cty.value=value;
						}
					}else if(cty.nodeName=="SELECT"){
						JBF.setOptionValue(cty,value);
					}else if(cty.nodeName=="DIV"||cty.nodeName=="TEXTAREA"){
							cty.innerHTML=value;	
					}
				}
			}
		},
		/**
		*得到check/radio组合的值，以数组形式返回
		*/
		getSubValues:function(cty){
			var str="";
			if(cty){
				for(var i=0;i<cty.length;i++){
					if(cty[i].checked){
						str+=cty[i].value+",";	
					}	
				}
				if(str.length>0){
					str=str.substr(0,str.length-1);	
				}
			}	
			return str;
		},
		/**
		 * 取父窗口中的url参数
		 */
		getParentUrlParams:function(params,paramName){
			 if(params==null){
				 params=window;
			 }
			 if(params.location||(""+params).indexOf("object Window")!=-1){
				 params=params.location.href;
			 }
			 var idx11=params.indexOf('?');
			 if(idx11!=-1){
				 params=params.substr(idx11+1);
			 }
			 selectIndex=null;
			 if(params&&params.length>0){
				params=params.replace("?","");//取参数，并且在参数中找选择的id号，如果有id号是修改,如果没有id号为新增
				var par=params.split("&");
				for(var i=0;i<par.length;i++){
					var subPar=par[i].split("=");
					if(subPar[0]==paramName){
						selectIndex=subPar[1];
						i=par.length;
					}
				}
			 }
			 return selectIndex;
		},
		/**
		*设置select控件的值
		*/
		setOptionValue:function(opt,value){
			if(opt){
				var opts=opt.options;
				for(var i=0;i<opts.length;i++){
					if(opts[i].value==value	){
						opts[i].selected=true;
						return;
					}
				}
			}
		},
		
		/**
		*设置check或radio控件的值
		*/
		setCheckValue:function(opt,values,type){
			 if(opt){
				if(type=="radio"){
					for(var i=0;i<opt.length;i++){
						var check=opt[i];
						if(check.value==values){
							check.checked=true;
							i=opt.length;
						}
					}	 
				}else if(type=="check"){
					for(var i=0;i<opt.length;i++){
						var check=opt[i];
						for(var j=0;j<values.length;j++){
							if(check.value==values[j]){
								check.checked=true;
								j=values.length;
							}
						}
					}	 
				}
			}
		},
		/**
		*增加事件
		**/
		addEvent: function( obj, eventName, fn){
			if( obj.attachEvent ){
				obj.attachEvent('on'+eventName, fn);
			}else if(obj.addEventListener){
				obj.addEventListener(eventName,fn, false);
			}else{
				obj["on"+eventName]=fn;	
			}
		},
		removeEvent:function(obj,eventName,fn){
			if(obj.removeEventListener){
				obj.removeEventListener(eventName,fn,false);
			}else if(obj.detachEvent){
				obj.detachEvent('on'+eventName,fn);
			}
		},
		/**
		*字符串转换成对象
		*/
		strToObj: function( s ){
			if( s && typeof(s) == 'string' ){
				try{
					return eval('('+s+')');
				}catch(e){
					return {};
				}
			}
		},
		/**
		*新建一按钮
		*/
		newButton: function(obj){
			var onClickStr="";
			if(!JBF.strIsNull(obj.showName)){
				obj.showName="默认按钮";
			}
			if(!JBF.strIsNull(obj.icon)){
				obj.icon="add";
			}
			if(obj.method){
				onClickStr="onclick='"+obj.method+"'";
			}
			var buttonStr="<input type='button' value='"+ obj.showName +"' style='BACKGROUND: url(JBFCommon/image/text-bg.gif)'"
			+" onmouseover='this.style.background = \"#ecbc01\"' "+ 
			" onmouseout='this.style.background = \"url(JBFCommon/image/text-bg.gif) repeat\"' "+onClickStr+"/>";
			var basicStr="<div class='basic-button-panel'"+onClickStr+" ><div class='basic-button-left'></div><div class='basic-button-middle'><div class='basic-button-text'><a href='javascript:void(0)'>"+obj.showName+"</a></div></div><div class='basic-button-right'></div></div>";
			//var buttonStr="<span class='btnLeft' "+onClickStr+"><span class='btnRight'><div class='btnText'><a  href='#'>"+obj.showName+"</a></div></span></span>";
			if(typeof(obj.click)=="function"){
				//JBF.onEvent("click",button,obj.click);
			}
			return {
				write:function(){
					JBF.doc.write(buttonStr);
				},
				append:function(){
					if(typeof(obj.appendObj)=='object'&&null!=obj.appendObj){
						//obj.appendObj.innerHTML+= buttonStr;
						obj.appendObj.innerHTML+=buttonStr;
					}
				},
				value:function(type){
					if(type){
						if(type=="icon"){
							return buttonStr;
						}else if(type=="basic"){
							return basicStr;
						}
					}
					return buttonStr;
				}
			};
		},
		getButtonsHTML:function(objs,type){
			var buttonHTML="";
			if(objs&&objs.length>0){
				for(var i=0;i<objs.length;i++){
					buttonHTML+=JBF.newButton(objs[i]).value(type);
				}
			}
			return buttonHTML;
		},
		getCopyButtonsHTML:function(objs,type){
			var buttonHTML="";
			if(objs&&objs.length>0){
				for(var i=0;i<objs.length;i++){
					if(objs[i].copy){
						buttonHTML+=JBF.newButton(objs[i]).value(type);
					}
				}
			}
			return buttonHTML;
		},
		getUrl:function(){
			//var host=window.location.host;
			var workName=window.location.pathname;
			if(workName.length>0&&workName.substring(0,1)=="/"){
				workName=workName.substring(1);
			}
			if(workName.indexOf("/")>-1){
				workName=workName.substring(0, workName.indexOf("/"));
			}
			var url="/"+workName+"/";
			return url;
		},
		getWorkName:function(){
			var workName=window.location.pathname;
			if(workName){
				if(workName.substring(0,1)=="/"){
					return workName.split("/")[1];
				}
			}
		},
		/**
		 * 根据节点名称获取了节点
		 */
		getSubNodesByNodeName:function(nodeName,parentNode){
			var returnNodes=new Array();
			var nodes=new Array();
			JBF.getAllSubNodes(nodes,parentNode);
			if(nodes.length>0){
				for(var i=0;i<nodes.length;i++){
					if(nodes[i].nodeName==nodeName){
						returnNodes.push(nodes[i]);
					}
				}
			}
			return returnNodes;
		},
		getParentNodeByClassName:function(className,childNode){
			var parentNode=childNode.parentNode;
			if(parentNode.nodeName!="BODY"){
				if(parentNode.className==className){
					return parentNode;
				}else{
					return JBF.getParentNodeByClassName(className,parentNode);
				}
			}
			if(parentNode.nodeName=="BODY"){
				return null;
			}
		},
		getParentNodeByNodeName:function(nodeName,childNode){
			var parentNode=childNode.parentNode;
			if(parentNode.nodeName!="BODY"){
				if(parentNode.nodeName==nodeName){
					return parentNode;
				}else{
					return JBF.getParentNodeByNodeName(nodeName,parentNode);
				}
			}
			if(parentNode.nodeName=="BODY"){
				return null;
			}
		},
		getAllSubNodes:function(childs,parentNode){
			if(parentNode&&parentNode.childNodes.length>0){
				for(var i=0;i<parentNode.childNodes.length;i++){
					var subNode=parentNode.childNodes[i];
					childs.push(subNode);
					if(document.all){
						JBF.getAllSubNodes(childs,subNode);
					}
				}
			}
		},
		initDatas:function(msg){
     		var columns=new Array();
     		var groups=new Array;
     		var maps=msg["viewDefMap"];
			if(maps){
				if(maps.viewGroups){
					for(var i=0;i<maps.viewGroups.length;i++){//分组信息
						var group=maps.viewGroups[i];
						var groupName=group["name"];
						var isShrink=group["isShrink"];
						var groupSpans=new Array();
						for(var j=0;j<group.viewItems.length;j++){//每组下的视图信息（columns）
							var viewItem=group.viewItems[j];
							if(maps.viewMode!=0){
								viewItem.display=viewItem.showName;
							}
							columns.push(viewItem);
							if(viewItem.type=="option"||viewItem.type=="radio"||viewItem.type=="check"){
								viewItem.value=JBF.strToObj(viewItem.value);
							}
							groupSpans.push(viewItem.name);
						}
						groups.push({"groupName":groupName,"spans":groupSpans,"type":"column","isShrink":isShrink});
					}
					maps.viewGroups=null;
					  if(maps.viewMode=="0"||groups.length>1){
							maps.groups=groups;
							maps.datas=columns;
						}else{
							maps.columns=columns;
						}
				}
			}
			return maps;
     	},
     	createAjaxDivAndShow:function(){
     		var div=JBF.el("ajaxFlushLoadingImage");
     		if(div){
     			if(div.style.display&&div.style.display=="none"){
     				div.style.display="inline";
     			}
     		}else{
    			var divPanel=document.createElement("div");
    			divPanel.setAttribute("id", "ajaxFlushLoadingImage");
    			divPanel.className="ajaxLoading";
    			divPanel.style.display="inline";
    			var divHeight=JBF.getScreenHeight();
    			var innerHTML="<div style='margin:auto;width:64px;margin-top:"+(divHeight/2-64)+"px;'><img width='64px' height='64px' src='"
    			                    +JBF.getUrl() +"JBFCommon/image/loading.gif' />载入数据.....</div>";
    			divPanel.style.height=divHeight;
    			divPanel.innerHTML=innerHTML;
    			document.body.appendChild(divPanel);
     		}
     	},
     	hideAjaxDiv:function(){
     		var div=JBF.el("ajaxFlushLoadingImage");
     		if(div){
     			div.style.display="none";
     		}
     	},
     	ajaxFlush:function(){
     	},
     	/*
     	 * url请求的url
     	 * params参数对像
     	 * fun回调方法
     	 * exceptionFun异常回调方法
     	 * ajaxStatus:同步异步状态,true:异步，false:同步
     	 */
     	ajax:function(url,params,fun,exceptionFun,ajaxStatus){
 			var paramStr=params;
 			if(typeof(params)=="object"){
 				paramStr=JBF.toUrlString(params);
 			}
 			if(!(url.indexOf(G_WebRoot)>-1)){
 				url=G_WebRoot+url;
 			}
 			if(typeof(ajaxStatus)=="BOOLEAR"){
 				if(ajaxStatus){
 					JBF.ajaxAsynchronism(url,params,fun,exceptionFun);
 				}else{
 					this.ajaxSynchronous(url,paramStr,fun,exceptionFun);
 				}
 			}else{
 				this.ajaxSynchronous(url,paramStr,fun,exceptionFun);
 			}
		},
		/**
		 * 数据异步请求
		 * @param url
		 * @param params
		 * @param fun
		 * @param exceptionFun
		 * @returns
		 */
	 	ajaxAsynchronism:function(url,params,fun,exceptionFun){
	 		JBF.createAjaxDivAndShow();	
			var msg=null;
			try{
				JBF.retrieveSynURL(url,params,true,function(req){//异步
					msg=JBF.strToObj(req.responseText);
					JBF.ajaxCallFun(msg,fun,exceptionFun);
				});
			}catch(e){}finally{
				JBF.hideAjaxDiv();
			}

		},
		/**
		 * 数据同步操作
		 * @param url
		 * @param params
		 * @param fun
		 * @param exceptionFun
		 * @returns
		 */
		ajaxSynchronous:function(url,params,fun,exceptionFun){
			var msg=null;
			JBF.retrieveSynURL(url,params,false,function(req){//false:同步
				msg=JBF.strToObj(req.responseText);
			});
			this.ajaxCallFun(msg,fun,exceptionFun);
		},
		ajaxCallFun:function(msg,fun,exceptionFun){
			if(msg&&msg.errorMessage){
				if(msg.code=="10000"){
					window.top.location.href=(G_WebRoot + "index.html");
				}else if(msg.code=="20000"){
					alert(msg.errorMessage);
					try{
						if(exceptionFun){
							if(typeof(exceptionFun)=="function"){
								exceptionFun();
							}else if(typeof(exceptionFun)=="string"){
								eval(exceptionFun+"()");
							}
						}
					}catch(e){
						alert("回调方法格式错误");
					}
				}else{
					alert(msg.errorMessage);
				}
				return;
			}else if(fun&&typeof fun=="function"){
				fun(msg);
			}else if(msg.successMessage){
				alert(msg.successMessage);
			}else{
				alert(msg.message);
			}
		},
		retrieveSynURL:function(url,data,callStatus,callFun) {
			var req="";
		    if (window.ActiveXObject) {
		    	req=new ActiveXObject("Microsoft.XMLHTTP");
		    }else if (window.XMLHttpRequest) { 
		    	req = new XMLHttpRequest();
		    }   
		    if(req){
				  try {
			      	req.open("POST", url, callStatus);//现在是同步操作(false=同步 true=异步)
			      	req.onreadystatechange = JBF.doHttpReadyStateChange(req,callFun); 
			      	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					req.setRequestHeader("X-Requested-With","ajax-request");;
					req.send(data);
				  } catch (e) {
				     alert("Problem Communicating with Server\n"+e);
				  };
		    };
		},
		doHttpReadyStateChange:function (req,callFun){
			return function(){
				if(req.readyState==4){
					if(req.status=="200"){
						callFun(req);
					}else if(req.status=="404"){
						alert("url重定向错误,服务可能已关闭！ \\n错误url");
					}else if(req.status=="500"){
						alert("系统内部错误");
					}
				}
			};
		},
		to16 : function(value) {
			var ten = parseInt(value / 16);
			var ge = value % 16;
			return JBF.conver16(ten) + "" + JBF.conver16(ge);
		},
		conver16 : function(value) {
			switch (value - 10) {
				case 0:
					return "A";
				case 1:
					return "B";
				case 2:
					return "C";
				case 3:
					return "D";
				case 4:
					return "E";
				case 5:
					return "F";
				default:
					return value;
			}
		},
		
		lastIndexStr:function(str,lastChar){
			while(str.indexOf(lastChar)>-1){
				str=str.substring(str.indexOf(lastChar)+1);
			}
			return str;
		},
		getFileName:function(str){
			var fileName=JBF.lastIndexStr(str,"/");
			return fileName.substring(fileName,fileName.indexOf("."));
		},
		getCookieByName:function(){
			var cookieStr=document.cookie;
			var name=JBF.getFileName(window.location.pathname);
			if(cookieStr.length>0){
				var cookies=cookieStr.split(";");
				for(var i=0;i<cookies.length;i++){
					cooks=cookies[i].split("=");
					var aa=cooks[0].replace(/^\s+|\s+$/g,"");   
					if(aa==name&&cooks.length>1){
						return cooks[1];
					}
				}
			}
		},
		/**
		 * 以天为单位
		 * @param time
		 * @param cookies
		 * @returns
		 */
		saveCookie:function(cookName,time,cookies){
			var name=JBF.getFileName(window.location.pathname);
			var date=new Date(); 
			//将date设置为10天以后的时间 
			date.setTime(date.getTime()+time*24*3600*1000); 
			//将userId和userName两个cookie设置为10天后过期 
			document.cookie=name+"="+cookies+";expires="+date.toGMTString();
		},
		showColorPanel:function(){
			JBF.closeColorPanel();
			var ev=arguments.callee.caller.arguments[0]||window.event;
			var obj= ev.srcElement|| ev.target;	
			configColorPanel=new ColorPanel("configColorPanel",obj);
			if(window.colorDiv){
				window.colorDiv.style.display="inline";
			}else{
				window.colorDiv=document.createElement("div");
				window.colorDiv.setAttribute("id", "colorPanelDiv1234567890");
				window.colorDiv.style.position="absolute";
				document.body.appendChild(window.colorDiv);
			}
			window.colorDiv.style.left=JBF.getAbsX(obj)+obj.offsetWidth;
			window.colorDiv.style.top=JBF.getAbsY(obj)-50;
			window.colorDiv.style.height="150px";
			window.colorDiv.innerHTML=configColorPanel.show(obj.value)+"<div style='float:right'><a href='javascript:void(0)' onclick='JBF.closeColorPanel();'>关闭</a></div>";
		},
		closeColorPanel:function(){
			if(window.colorDiv){
				window.colorDiv.style.display="none";
				window.event.cancelBubble=true;
			}
		},
		serialize:function(obj,name)
		{
			return encodeURI(serialize1(obj,name));
			function serialize1(obj,name)
			{
				if(obj){ 
					switch(obj.constructor)
					{
						case Array://类型是数组 返回 name[0]=obj[0]&name[1]=obj[1]&...
							var s = "";
							for(var i=0;i<obj.length;i++)
							{
								var subName=name+"["+i+"]";
								s = s +serialize1(obj[i],subName);
							}					
							return s;
						case Object://类型是对象 name.param1=obj.param1&...
							var s = "";
							for(var p in obj)
							{
								var subName=name+"."+p;
								s = s +serialize1(obj[p],subName);
							}
							return s;
						default://类型是string 返回 name=obj& 
							return "&"+name+"="+obj;
					}	
				}else
				{ 
					return "";
				}
			}
		},
		/**
		 * 获取URL中的参数
		 * @param name 参数名称
		 * @returns
		 */
		getURLParameter : function(name){
		  var search = document.location.search;
		  var pattern = new RegExp("[?&]"+name+"\=([^&]+)", "g");
		  var matcher = pattern.exec(search);
		  var items = null;
		  if(null != matcher){
		    try{
		      items = decodeURIComponent(decodeURIComponent(matcher[1]));
		    }catch(e){
		      try{
		              items = decodeURIComponent(matcher[1]);
		      }catch(e){
		              items = matcher[1];
		      }
		    }
		  }
		  return items;
		},		
	// javascript对象转 JSON 数据对象。
		toJSONString : function (txtOrObj){
			var data=txtOrObj;
			if(typeof data=='string') try{data=eval('('+data+')');}catch(e){return "";};
			var draw=new Array();
//			var last=false;
			var isLast=true;
//			var indent=0;
			function notify(name,value,isLast,formObj){
				if(value&&value.constructor==Array){
					draw.push((formObj?('"'+name+'":'):'')+'[');
					for (var i=0;i<value.length;i++) notify(i,value[i],i==value.length-1,false);
					draw.push(']'+(isLast?'':(',')));
				}else	if(value&&typeof value=='object'){
					draw.push((formObj?('"'+name+'":'):'')+'{');
					var len=0,i=0;
					for(var key in value)len++;
					for(var key in value)notify(key,value[key],++i==len,true);
					draw.push('}'+(isLast?'':(',')));
				}else{
					if(typeof value=='string')value='"'+value+'"';
					draw.push((formObj?('"'+name+'":'):'')+value+(isLast?'':','));
				};
			};
			notify('',data,isLast,false);
			return draw.join('');
		},
		/**
		 * 将对像转换成url参数
		 * @param obj1
		 * @returns
		 */
  		toUrlString:function(obj1){
			var urlStr="";
			(function(obj,str){
				if(typeof(obj)=="object"){
					for(var attName in obj){
						var subObj=obj[attName];
						var prefix=str;
						if(typeof(subObj)=="object"&&subObj.constructor==Array){
							for(var i=0;i<subObj.length;i++){
								prefix+=("."+attName)+"["+i+"]";
								arguments.callee(subObj[i],prefix);
							}
						}else if(typeof(subObj)=="object"){
							prefix+=("."+attName);
							arguments.callee(subObj,prefix);
						}else{
							if(prefix.substring(0,1)=="."){
								prefix=prefix.substring(1);
							}
							urlStr+="&"+prefix+"."+attName+"="+obj[attName];
						}
					}
				}
			})(obj1,"");
			return urlStr;
		},
		
		setFocusStyle:function(obj,isShowTip,tipText){
			var node = this.getParentNodeByNodeName("TD", obj);
			if(obj.getAttribute("parentTable") && obj.getAttribute("parentTable") != ""){
				node = this.getParentNodeByNodeName("TD",this.getParentNodeByNodeName("DIV", obj));
			}
			var preNode = node.previousSibling;
			preNode.style.backgroundColor = '#CCC';
			var newObj=obj;
			if(obj.type == "radio"){
				node = this.getParentNodeByNodeName("SPAN",obj);
				node.style.border='1px solid #ff0000';
				newObj=node;
			}else{
				obj.style.border='1px solid #ff0000';
				newObj=obj;
			}
			if(isShowTip&&newObj&&tipText){
				JBF.createFocusTip(obj,tipText);
			}
		},
		createFocusTip:function(element,showText){
			focusTipName="focusTipInput";
			var tipDiv=JBF.el(focusTipName);
			if(!tipDiv){
				tipDiv=document.createElement("div");
				tipDiv.setAttribute("name", focusTipName);
				tipDiv.setAttribute("id", focusTipName);
			}else{
				tipDiv.style.display="inline";
			}
			tipDiv.innerHTML="<div class='topSpan'></div><div class='contentSpan'><div class='innerSpan'><div class='text'>"+showText+"</div></div></div>";
			tipDiv.className="tipFrame";
			tipDiv.style.left=(JBF.getAbsX(element)+20)+"px";
			tipDiv.style.top=(JBF.getAbsY(element)+JBF.getObjHeight(element)-JBF.getScrollTop(element))+"px";
			document.body.appendChild(tipDiv);
		},
		setBlurStyle:function(obj){
			var node = this.getParentNodeByNodeName("TD", obj);
			if(obj.getAttribute("parentTable") && obj.getAttribute("parentTable") != ""){
				node = this.getParentNodeByNodeName("TD",this.getParentNodeByNodeName("DIV", obj));
			}
			var preNode = node.previousSibling;
			preNode.style.backgroundColor = '';
			if(obj.type == "radio"){
				node = this.getParentNodeByNodeName("SPAN",obj);
				node.style.border='1px solid #9cb3e2';
			}else{
				obj.style.border='1px solid #9cb3e2';
			}
			var tipDiv=JBF.el("focusTipInput");
			if(tipDiv){
				tipDiv.style.display="none";
			}
		},
		
		/**
		 * 文本域长度限制
		 * el 文本域对象 len 最长输入数字
		 */ 
		limitTextareaLength:function(el,len){
			if(el&&el.value){
				var maxLength=el.value.replace(/[^\x00-\xff]/g, 'AA').length;
				if (maxLength > len){
					el.value = el.value.substring(0, len);
				}	
			}
		},
		openWinByUrl : function(url, width, height) {
			var openWinStyle = " status=no; scroll=no; resizable=no;";// 用于简单的增删改查操作
			var defaultStyle="";
			if(width&&height){
				defaultStyle= "dialogWidth=" + width + "px;dialogHeight=" + height+ "px";
			}else{
				defaultStyle="dialogWidth=" + (window.screen.availWidth )+ "px;dialogHeight=" + (window.screen.availHeight) + "px";
			}
			//window.open(url);
			var returnValue=window.showModalDialog(url, window, defaultStyle+openWinStyle);
			return returnValue;
		}
		
	};
})();


JBF.G_WebRoot = '/'+(window.location.pathname.indexOf('/')==0?window.location.pathname.split('/')[1]:window.location.pathname.split('/')[0])+'/';